package com.ljw.community.mapper;

import com.ljw.community.entity.User;
import com.ljw.community.service.SqlService;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select(value = "select * from user where login_name = #{loginName} and del_flag = 0")
    User getByLoginName(String loginName);


    /**获取包括删除了的
     */
    @Select(value = "select * from user where login_name = #{loginName}")
    User getFullByLoginName(String loginName);

    @InsertProvider(type = SqlService.class, method = "insertUserProvider")
    int insert(User user);

    @UpdateProvider(method = "updateByLoginNameProvider", type = SqlService.class)
    int updateByLoginName(User user);

    //获取待审核的
    @Select(value = "select * from user where state = '0' and del_flag = '0' order by create_time desc limit ${start},${limit}")
    List<User> loadUnverifiedUser(int start ,int limit);

    //获取所有已通过审核用户
    @Select(value = "select * from user where state not in ('0','-1') and del_flag = '0' and (name like '%${query}%' or" +
            " login_name like '%${query}%')  order by create_time desc limit ${start},${limit}")
    List<User> loadUserList(int start, int limit, String query);
}
